package com.koron.css2.newProjectCenter.mapper;

import com.koron.css2.newProjectCenter.bean.PjPubUpMaterial;
import com.koron.css2.newProjectCenter.bean.Warehouse;
import com.koron.css2.newProjectCenter.bean.query.PjPubUpMaterialQuery;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author: 苏小龙
 * @CreateTime: 2024-12-04
 * @Description: 材料信息
 * @Version: 1.0
 */
public interface PjPubUpMaterialMapper {

    List<PjPubUpMaterial> getList(PjPubUpMaterialQuery pjPubUpMaterialQuery);

    @Select("select * from pub_up_material where id = #{id} and is_deleted = false")
    PjPubUpMaterial getMaterialById(String id);

    int deleteById(String id);

    void insert(PjPubUpMaterial pjPubUpMaterial);
    void update(PjPubUpMaterial pjPubUpMaterial);

    @Select("select name from pub_up_dealings where id = #{manufacturerId} and is_deleted = false")
    String getNameById(String manufacturerId);

    @Select("select store_name name from pub_up_store where id = #{materialId} and is_deleted = false")
    String getMaterialNameById(String materialId);

    @Select("select count(0) from pub_up_material where is_deleted = false and type_id = #{typeId} ")
    int getAllCountByTypeId(@Param("typeId") String typeId);

    @Insert("insert into pj_material_store" +
            "(id, material_id, quantity, original_quantity, warehouse_id, create_name, update_name, create_account, update_account) value " +
            "(#{id} , #{materialId} , #{quantity} ,#{quantity} , #{warehouseId} , #{createName} , #{updateName} , #{createAccount} , #{updateAccount})")
    void insertIntoStore(Warehouse warehouse);

    @Select("select * from pj_material_store where is_delete = false and material_id = #{id} ")
    List<Warehouse> getStoreList(@Param("id") String id);

    @Select("select sum(quantity) from pj_material_store where is_delete = false and material_id = #{materialId}")
    Integer getTotalQuantityByMaterialId(@Param("materialId") String materialId);
}
